#ifndef _RECEIVEBUFFER_H_
#define _RECEIVEBUFFER_H_


#include <winsock2.h>
#include <utillib/memory/LinearBuffer.h>

namespace netlib
{
	namespace packet
	{
		enum DispatchEvent
		{
			Dispatch_None		=	0,
			Dispatch_Accept	=	1,
			Dispatch_Connect	=	2,
			Dispatch_Send		=	4,
			Dispatch_Receive	=	8,
			Dispatch_Close		=	16,
			Dispatch_ReadySend	=	32,
			Dispatch_ReadyReceive	=	64,
			Dispatch_Except	=	128,
		};
		struct SocketEvent
		{
			DispatchEvent m_event;
			int m_errorCode;
			size_t m_size;
			unsigned char *m_ptr;
		};

		class PacketQueue
		{
		public:
			PacketQueue( size_t capacity );
			~PacketQueue();

			bool pop( SocketEvent *socketEvent );
			size_t size() const;
			bool empty() const;

		private:
			bool push( DispatchEvent dispatchEvent, unsigned char*ptr, size_t size, int errorCode );
			void clear();

			void resize();

		private:
			utillib::memory::LinearBuffer m_buffer;
			size_t m_size;
		};
	}
}

#endif //__RECEIVEBUFFER_H__